<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-button type="success" icon="plus" @click="addadmin" v-qx="quanxian.add">管理员</el-button>
            <el-button type="primary" icon="h-refresh1" @click="getmsg" style="float:right">刷新列表</el-button>
        </div>
        <el-table :data="adminlist" :stripe="true" height="100%">
            <el-table-column prop="id" label="#"></el-table-column>
            <el-table-column prop="name" label="用户名"></el-table-column>
            <el-table-column prop="username" label="账号"></el-table-column>
            <el-table-column prop="phone" label="手机号"></el-table-column>
            <el-table-column prop="remarks" label="描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="gradeid" label="权限等级"></el-table-column>
            <el-table-column label="设置">
                <template slot-scope="scope">
                    <el-button-group>
                        <el-button type="warning" icon="el-icon-edit" size="mini" v-qx="quanxian.edit" @click="edit(scope.row)"></el-button>
                        <el-tooltip content="选择权限等级" placement="top" :open-delay="800" v-qx="quanxian.set">
                            <el-button icon="el-icon-h-set2" type="primary" size="mini" @click="selectrule(scope.row)"></el-button>
                        </el-tooltip>
                        <!-- <el-button icon="delete2" type="danger" size="small"  @click="deladmin(scope.row.id)" v-qx="quanxian.del"></el-button> -->
                    </el-button-group>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import C from '#/src/common/common.js'
import Rule from '#/src/shop/rule.js'

export default {
    name: 'adminRule',
    data() {
        return {
            adminlist: [],
            quanxian: {
                add: 'zhanghao_add',
                edit: 'zhanghao_edit',
                set: 'zhanghao_set',
                del: 'zhanghao_del',
            },
            noadd: true
        }
    },
    methods: {
        addadmin: async function() {
            let res = await Rule.openAddAdmin()
            if (res && res.data) {
                C.success(res.data)
                this.getmsg()
            }
        },
        edit: async function(row) {
            let res = await Rule.openAddAdmin(row)
            if (res && res.data) {
                C.success(res.data)
                this.getmsg()
            }
        },
        selectrule: async function(row) {
            let res = await C.openBrowserWindow('/selectGrade', { id: row.id, gid: row.groupid }, { width: 800, height: 800, useSpa: true, spaModel: 'shop', transparent: true, frame: false })
            if (res) {
                C.success(res.data)
                this.getmsg()
            }
        },
        deladmin: function(id) {
            C.confirm('确定删除当前管理员？', async() => {
                let data = await C.ajax('/shop/rule/delshopadmin', { id: id }, 'post')
                if (data) {
                    C.success(data.data.info)
                    this.getmsg()
                }
            })
        },
        getmsg: async function() {
            var that = this
            let data = await C.ajax('/shop/rule/getadminlist', {}, 'post')
            if (data) {
                that.adminlist = data
                if (data.length > 15) {
                    that.noadd = false
                } else {
                    that.noadd = true
                }
            }
        },
    },
    mounted: function() {
        this.getmsg()
    }
}
</script>